package app.android.com.wuandroidapp.test.view.definedview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2017/8/1.
 */

public class CirClegView extends View {
    Paint paint1;
    int length;
    public CirClegView(Context context) {
        super(context);
        paint1=new Paint();
        paint1.setStyle(Paint.Style.FILL);
        paint1.setColor(Color.YELLOW);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }

    public CirClegView(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint1=new Paint();
        paint1.setStyle(Paint.Style.FILL);
        paint1.setColor(Color.YELLOW);

    }

    public CirClegView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        length=getWidth();
        int mCircleXY=length/2;
        float mRadius= (float) (mCircleXY*0.5/2);
        canvas.drawCircle(mCircleXY,mCircleXY,mRadius,paint1);

        RectF mArcRectF =new RectF((float)( length*0.1),(float)( length*0.1),(float)( length*0.9),(float)( length*0.9));
        paint1.setStyle(Paint.Style.STROKE);
        paint1.setStrokeWidth(20);
        canvas.drawArc(mArcRectF,90,270,false,paint1);

        paint1.setStyle(Paint.Style.FILL);
        paint1.setColor(Color.BLUE);
        paint1.setTextSize(16);
        canvas.drawText("你好啊,先生",0,"你好啊,先生".length(),mCircleXY-(16*"你好啊,先生".length())/2,mCircleXY+(16/2),paint1);

    }
}
